/**
 * FtpTaskEditPane.java
 * @author Daniel Liu
 * Create: 2007-1-4 ����10:44:36
 * NOTE: 
 */
package org.lex.ftp.ui.queue;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.*;

import org.lex.ftp.queue.Task;
import org.lex.io.filesystem.FileNameUtilities;


public class TaskEditorPane extends JPanel {
	private JLabel hostLabel = null;
	private JTextField hostTextField = null;
	private JButton hostButton = null;
	private JLabel pathLabel = null;
	private JTextField pathTextField = null;
	private JButton pathButton = null;
	private JLabel nameLabel = null;
	private JTextField fileTextField = null;
	private JButton nameButton = null;

	public TaskEditorPane() {
		super();
		initialize();
	}

	public void setSource(Task task) {
		this.setHost(task.getURL().getServer());
		String path = task.getSource();
		this.setPath(FileNameUtilities.getParentPath(path, '/'));
		this.setFile(FileNameUtilities.getFileName(path, '/'));
	}

	public void setTarget(Task task) {
		this.setHost(task.getDestination());
		String path = task.getDestination();
		this.setPath(FileNameUtilities.getParentPath(path));
		this.setFile(FileNameUtilities.getFileName(path));
	}

	String getHost() {
		return this.getHostTextField().getText().trim();
	}

	void setHost(String host) {
		this.getHostTextField().setText(host);
	}

	String getPath() {
		return this.getPathTextField().getText().trim();
	}

	void setPath(String path) {
		this.getPathTextField().setText(path);
	}

	String getFile() {
		return this.getFileTextField().getText().trim();
	}

	void setFile(String name) {
		this.getFileTextField().setText(name);
	}

	// =======================
	private void initialize() {
		GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
		gridBagConstraints9.gridx = 0;
		gridBagConstraints9.gridwidth = 3;
		gridBagConstraints9.fill = GridBagConstraints.BOTH;
		gridBagConstraints9.weightx = 1.0;
		gridBagConstraints9.weighty = 1.0;
		gridBagConstraints9.gridy = 3;
		GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
		gridBagConstraints8.gridx = 2;
		gridBagConstraints8.insets = new Insets(0, 5, 7, 5);
		gridBagConstraints8.gridy = 2;
		GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
		gridBagConstraints7.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints7.gridy = 2;
		gridBagConstraints7.weightx = 1.0;
		gridBagConstraints7.insets = new Insets(0, 5, 7, 0);
		gridBagConstraints7.gridx = 1;
		GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
		gridBagConstraints6.gridx = 0;
		gridBagConstraints6.insets = new Insets(0, 6, 7, 0);
		gridBagConstraints6.anchor = GridBagConstraints.WEST;
		gridBagConstraints6.gridy = 2;
		nameLabel = new JLabel();
		nameLabel.setText("File");
		GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
		gridBagConstraints5.gridx = 2;
		gridBagConstraints5.insets = new Insets(0, 5, 6, 5);
		gridBagConstraints5.gridy = 1;
		GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
		gridBagConstraints4.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints4.gridy = 1;
		gridBagConstraints4.weightx = 1.0;
		gridBagConstraints4.insets = new Insets(0, 5, 0, 0);
		gridBagConstraints4.gridx = 1;
		GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
		gridBagConstraints3.gridx = 0;
		gridBagConstraints3.insets = new Insets(0, 6, 5, 0);
		gridBagConstraints3.anchor = GridBagConstraints.WEST;
		gridBagConstraints3.gridy = 1;
		pathLabel = new JLabel();
		pathLabel.setText("Path");
		GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
		gridBagConstraints2.gridx = 2;
		gridBagConstraints2.insets = new Insets(8, 5, 6, 5);
		gridBagConstraints2.gridy = 0;
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
		gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
		gridBagConstraints1.gridy = 0;
		gridBagConstraints1.weightx = 1.0;
		gridBagConstraints1.insets = new Insets(8, 5, 0, 0);
		gridBagConstraints1.gridx = 1;
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.insets = new Insets(8, 6, 5, 0);
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.gridy = 0;
		hostLabel = new JLabel();
		hostLabel.setText("Host");
		this.setLayout(new GridBagLayout());
		this.add(hostLabel, gridBagConstraints);
		this.add(getHostTextField(), gridBagConstraints1);
		this.add(getHostButton(), gridBagConstraints2);
		this.add(pathLabel, gridBagConstraints3);
		this.add(getPathTextField(), gridBagConstraints4);
		this.add(getPathButton(), gridBagConstraints5);
		this.add(nameLabel, gridBagConstraints6);
		this.add(getFileTextField(), gridBagConstraints7);
		this.add(getNameButton(), gridBagConstraints8);
		this.add(Box.createGlue(), gridBagConstraints9);
	}

	private JTextField getHostTextField() {
		if (hostTextField == null) {
			hostTextField = new JTextField();
		}
		return hostTextField;
	}

	private JButton getHostButton() {
		if (hostButton == null) {
			hostButton = new JButton();
			hostButton.setText("..");
		}
		return hostButton;
	}

	private JTextField getPathTextField() {
		if (pathTextField == null) {
			pathTextField = new JTextField();
		}
		return pathTextField;
	}

	private JButton getPathButton() {
		if (pathButton == null) {
			pathButton = new JButton();
			pathButton.setText("..");
		}
		return pathButton;
	}

	private JTextField getFileTextField() {
		if (fileTextField == null) {
			fileTextField = new JTextField();
		}
		return fileTextField;
	}

	private JButton getNameButton() {
		if (nameButton == null) {
			nameButton = new JButton();
			nameButton.setText("..");
			nameButton.setText("...");
		}
		return nameButton;
	}
}
